package com.suiwei.webservice.base.wsClient.client;

import com.suiwei.webservice.base.wsClient.interceptor.ClientLoginInterceptor;
import org.apache.cxf.endpoint.Client;import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

/**
 * @author suiwei
 * @date 2023/4/24 21:20
 * 基于动态模式，带验证
 */
public class CXFClientDynamic {
  public static void main(String[] args) throws Exception {
    String address = "http://127.0.0.1:9090/greet?wsdl";
    //JaxWsDynamicClientFactory 只要指定服务器端wsdl文件的位置，然后指定要调用的方法和方法的参数即可，不关心服务端的实现方式
    JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
    Client client = dcf.createClient(address);//创建一个客户端类
    client.getOutInterceptors().add(new ClientLoginInterceptor("suiwei","suiwei"));
    Object[] objects = client.invoke("greeting","sw");
    System.out.println(objects[0]);
  }
}
